package com.seven.tools.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 用于 BaseJsonEnum 的子类解析成json格式，一般在api中注入此解析器
 *
 * @author seven
 */
public class BaseJsonEnumSerializer extends JsonSerializer<BaseJsonEnum> {

    @Override
    public void serialize(BaseJsonEnum value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        Map<String, String> map = new HashMap<>();
        map.put("code", value.getCode());
        map.put("des", value.getDes());
        gen.writeObject(map);
    }

}